package com.smile.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.spring.SaBeanInject;
import cn.hutool.core.bean.BeanUtil;
import com.smile.commons.page.R;
import com.smile.model.dto.request.GetUserInfoByUserNameRequestDTO;
import com.smile.model.response.response.GetUserInfoByUserNameResponseDTO;
import com.smile.model.request.GetUserInfoByUserNameRequest;
import com.smile.model.response.GetUserInfoByUserNameResponse;
import com.smile.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private SaBeanInject saBeanInject;

    @SaIgnore
    @PostMapping(value = "/getUserInfoByUserName", produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_HTML_VALUE})
    public R<GetUserInfoByUserNameResponse> getUserInfoByUserName(@RequestBody GetUserInfoByUserNameRequest getUserInfoByUserNameRequest) {
        GetUserInfoByUserNameRequestDTO getUserInfoByUserNameRequestDTO = new GetUserInfoByUserNameRequestDTO();
        BeanUtil.copyProperties(getUserInfoByUserNameRequest, getUserInfoByUserNameRequestDTO);
        GetUserInfoByUserNameResponseDTO getUserInfoByUserNameResponseDTO = userService.getUserInfoByUserName(getUserInfoByUserNameRequestDTO);
        GetUserInfoByUserNameResponse getUserInfoByUserNameResponse = BeanUtil.copyProperties(getUserInfoByUserNameResponseDTO, GetUserInfoByUserNameResponse.class);
        return R.ok(getUserInfoByUserNameResponse);
    }
}
